""" 
按行读取效率最高: for line in file
按块读取: 可以使用 yield
"""
def read_file_line(file_name):
    """ 
    按行读取文件
    """
    with open(file_name, "r") as fp:
        for line in fp:
            yield line

def read_file_in_chunks(filename, chunk_size=1024):
    """ 
    按块读取文件
    """
    with open(filename, 'r') as file:
        while True:
            chunk = file.read(chunk_size)
            if not chunk:
                break
            yield chunk

# 模拟readline(), 每次读取一行
for line in read_file_line("test.txt"):
    print(line, end="")
print("\nEnd---------")
